package com.likersai.opon.controller;

import com.likersai.opon.pojo.entity.ToxicSaying;
import com.likersai.opon.pojo.bo.ResponseBO;
import com.likersai.opon.pojo.vo.req.ToxicSayingReq;
import com.likersai.opon.pojo.vo.rsp.ToxicSayingRsp;
import com.likersai.opon.service.ToxicSayingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

/**
 * 毒鸡汤对外接口
 *
 * @author sun.ye
 * @since 2021-01-13 22:45
 */
@Api(value = "毒鸡汤", tags = "毒鸡汤相关")
@RestController
public class ToxicSayingController {



    private final ToxicSayingService toxicSayingService;

    public ToxicSayingController(ToxicSayingService toxicSayingService) {
        this.toxicSayingService = toxicSayingService;
    }
    
    @ApiOperation(value = "随机查询一条名言", notes = "获取一条随机的毒鸡汤")
    @GetMapping(value = "/randomToxicSaying",produces = "application/json;charset=UTF-8")
    public ResponseBO<ToxicSayingRsp> getRandomToxicSaying(){
        ToxicSayingRsp rsp = toxicSayingService.queryRandomOne();
        return ResponseBO.getSuccess(rsp);
    }
    
    @ApiOperation(value = "添加一条毒鸡汤", notes = "添加一条毒鸡汤")
    @PostMapping("/toxicSaying")
    public ResponseBO<ToxicSayingRsp> addToxicSaying (@RequestBody ToxicSayingReq req){
        ToxicSayingRsp rsp = toxicSayingService.saveOne(req);
        return ResponseBO.getSuccess(rsp);
    }
    
    @ApiOperation(value = "修改毒鸡汤", notes = "修改一条毒鸡汤")
    @PutMapping("/toxicSaying")
    public ResponseBO<ToxicSayingRsp> modToxicSaying (@RequestBody ToxicSayingReq req){
        ToxicSayingRsp rsp = toxicSayingService.modifyToxicSaying(req);
        return ResponseBO.getSuccess(rsp);
    }

}